package com.atguigu.gulimall.order.web;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.atguigu.gulimall.order.config.AlipayTemplate;
import com.atguigu.gulimall.order.service.OrderService;
import com.atguigu.gulimall.order.vo.PayAsyncVo;
import com.atguigu.gulimall.order.vo.PayVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@Controller
@Slf4j
public class PayWebController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private AlipayTemplate alipayTemplate;

    @GetMapping(value = "/order/pay/{orderSn}", produces = MediaType.TEXT_HTML_VALUE)
    @ResponseBody
    public String alipay(@PathVariable("orderSn") String orderSn) throws AlipayApiException {
        PayVo vo = orderService.getOrderPayVo(orderSn);
        return alipayTemplate.pay(vo);
    }
}
